package compress;

import priv.dengjl.compress.util.CompressUtil;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 *   select col1, col2, concat_ws('|', collect_set(cast(col3 as string))) as col3
 *   from row2col_1
 *   group by col1, col2;
 */
public class CompressTest3 {


	public static byte[] generateString() throws Exception {
		byte[] bytes = new byte[10485756];
		InputStream fis = new FileInputStream("data/00000000000048493522.timeindex");
		BufferedInputStream bis = new BufferedInputStream(fis);

		int len = 0;
		int count =0;
		while((len = bis.read()) != -1) {

			bytes[count] = (byte) len;
			count++;
		}
		//System.out.println("count"+count);
		bis.close();
		return bytes;
	}

	public static void main(String[] args) throws Exception {

		byte[] dataBytes = generateString();
		System.out.println("压缩前数据大小：" + dataBytes.length);

		CompressUtil[] values = CompressUtil.values();
		for (int i = 1; i <= 5; i++) {

			System.out.println("测试第"+i+"次结果");

			for (CompressUtil compressUtil : values) {
				System.out.println("===================: " + compressUtil.name());
				long start = System.currentTimeMillis();
				byte[] resultBytes = compressUtil.compress(dataBytes);
				System.out.println("压缩后数据大小:" + resultBytes.length);
				System.out.println("压缩时间(ms)：" + (System.currentTimeMillis() - start));

				long start2 = System.currentTimeMillis();
				byte[] uncompressBytes = compressUtil.uncompress(resultBytes);
				System.out.println("解压后数据大小：" + uncompressBytes.length);
				String result = new String(uncompressBytes);
				// System.out.println("解压后数据内容：" + result);
				System.out.println("解压时间(ms)：" + (System.currentTimeMillis() - start2));
				System.out.println("===================: " + compressUtil.name());
				System.out.println();
			}
		}


	}

}
